clear all

*Define global path for replication package
global path "~/Dropbox/IT_Revolution/Replication_package/JPE submission"

global path_rawdata "$path/Raw_data"
global path_cleandata "$path/Clean_data"
global path_output "$path/Output"

cap mkdir "$path_output"

*** Estimate regressions for ICT exposure, 1980-2019
********************************************************************************
use "$path_cleandata/data_occ_1980_2010_s1_a29distance.dta", clear

*Step 1. Create variables for estimation
********************************************************************************
foreach var of varlist emp1980 emp1990 emp2000 emp2010 emp2018 {
	egen tot_emp = sum(`var'), by(group)
	replace `var' = `var'/tot_emp
	drop tot_emp
}

*create variables for regressions
gen change_emp1 = log(emp1990/emp1980)
gen change_emp2 = log(emp2000/emp1980)
gen change_emp3 = log(emp2010/emp1980)
gen change_emp4 = log(emp2018/emp1980)

gen change_inc1  = lavgwage1990  - lavgwage1980 
gen change_inc2  = lavgwage2000  - lavgwage1980
gen change_inc3  = lavgwage2010  - lavgwage1980
gen change_inc4  = lavgwage2018  - lavgwage1980 

*select occupations with positive employment in 1980 and 2018
gen aind = change_emp4 != .
egen ind = sum(aind), by(occ1990dd)
keep if ind == 3

*weights
gen aemp1980 = emp1980 if group == 0
egen emp_all0 = mean(aemp1980), by(occ1990dd)

*standardized regressors
foreach var of varlist task_abstract ict {
	sum `var' if group == 0 [aw=emp_all0]
	gen exposure_`var' = (`var' - `r(mean)')/`r(sd)' 
}
rename exposure_task_abstract exposure_a
egen aad_ent = std(ad_ent)

*Step 2. Regressions for all workers - Figure 1.A and 1.B 
********************************************************************************
local exposure exposure_ict
local controls
	
foreach p of numlist 1/4 {
	reg change_emp`p' `exposure' `controls' if group == 0 [aw = emp_all0]  , cluster(occ1990dd)
	est store per`p'_emp
	
	reg change_inc`p' 	`exposure' `controls' if group == 0 [aw = emp_all0]  , cluster(occ1990dd)
	est store per`p'_inc
}
 
*Step 3. Regressions for worker generations - Figure 1.C and 1.D 
********************************************************************************
local exposure exposure_ict
local controls

foreach p of numlist 1/4 {
	reg change_emp`p' c.`exposure'#i.group i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group_emp
	
	reg change_inc`p' 	c.`exposure'#i.group i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group_inc
}

* Step 4: Baseline specification for Table A2
********************************************************************************
gen variable = `exposure'
gen aux_variable = .

local exposure exposure_ict
local controls 

foreach p of numlist 1 2 3 4 {
		
	replace variable = `exposure'
	replace aux_variable = .
	reg change_emp`p' variable `controls' if group == 0 [aw = emp_all0]  , cluster(occ1990dd)
	est store per`p'_emp_base
	reg change_inc`p' variable `controls' if group == 0 [aw = emp_all0]  , cluster(occ1990dd)
	est store per`p'_inc_base
	
	replace variable = c.`exposure'#1.group
	replace aux_variable = c.`exposure'#2.group
	reg change_emp`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group1_emp_base
	reg change_inc`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group1_inc_base
	
	replace variable = c.`exposure'#2.group
	replace aux_variable = c.`exposure'#1.group
	reg change_emp`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group2_emp_base
	reg change_inc`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group2_inc_base
	
	replace variable = c.`exposure'#1.group
	replace aux_variable = c.`exposure'#2.group
	reg change_emp`p' `exposure' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_dgroup_emp_base
	reg change_inc`p' `exposure' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_dgroup_inc_base
	
}

* Step 5: Robustness wrt exposure measure for Table A2
********************************************************************************
local controls 

foreach exposure of varlist exposure_a {
	foreach p of numlist 2 4 {
		replace variable = `exposure'
		replace aux_variable = .
		reg change_emp`p' variable `controls' if group == 0 [aw = emp_all0]  , cluster(occ1990dd)
		est sto per`p'_emp_`exposure'
		reg change_inc`p' variable `controls' if group == 0 [aw = emp_all0]  , cluster(occ1990dd)
		est sto per`p'_inc_`exposure'
		
		replace variable = c.`exposure'#1.group
		replace aux_variable = c.`exposure'#2.group
		reg change_emp`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
		est sto per`p'_group1_emp_`exposure'
		reg change_inc`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
		est sto per`p'_group1_inc_`exposure'
		
		replace variable = c.`exposure'#2.group
		replace aux_variable = c.`exposure'#1.group
		reg change_emp`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
		est sto per`p'_group2_emp_`exposure'
		reg change_inc`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
		est sto per`p'_group2_inc_`exposure'
		
		replace variable = c.`exposure'#1.group
		replace aux_variable = c.`exposure'#2.group
		reg change_emp`p' `exposure' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
		est sto per`p'_dgroup_emp_`exposure'
		reg change_inc`p' `exposure' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
		est sto per`p'_dgroup_inc_`exposure'	
	}
}

* Step 6: Robustness wrt controls for Table A2
********************************************************************************
local exposure exposure_ict
local controls hours1980 full_time1980 self_employed1980

foreach p of numlist 2 4 {
	replace variable = `exposure'
	replace aux_variable = .
	reg change_emp`p' variable `controls' if group == 0 [aw = emp_all0]  , cluster(occ1990dd)
	est sto per`p'_emp_controls
	reg change_inc`p' variable `controls' if group == 0 [aw = emp_all0]  , cluster(occ1990dd)
	est sto per`p'_inc_controls
	
	replace variable = c.`exposure'#1.group
	replace aux_variable = c.`exposure'#2.group
	reg change_emp`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group1_emp_controls
	reg change_inc`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group1_inc_controls
	
	replace variable = c.`exposure'#2.group
	replace aux_variable = c.`exposure'#1.group
	reg change_emp`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group2_emp_controls
	reg change_inc`p' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_group2_inc_controls
	
	replace variable = c.`exposure'#1.group
	replace aux_variable = c.`exposure'#2.group
	reg change_emp`p' `exposure' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_dgroup_emp_controls
	reg change_inc`p' `exposure' variable aux_variable i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per`p'_dgroup_inc_controls
}

* Step 7: Employment by exposure and distance groups for Figure 2
********************************************************************************
use "$path_cleandata/data_occ_1980_2010_s1_a29distance.dta", clear

*create variables for regressions)
gen change_emp4 = log(emp2018/emp1980)

*select occupations with positive employment in 1980 and 2018
gen aind = change_emp4 != .
egen ind = sum(aind), by(occ1990dd)
keep if ind == 3

foreach var of varlist task_abstract ict {
	sum `var' if group == 0 
	gen exposure_`var' = (`var' - `r(mean)')/`r(sd)' 
}
rename exposure_task_abstract exposure_a

*define groups of high/low exposure and distance
local exposure ict
local dist ad_ent

sum `exposure' if group == 0 , d
gen high_exp = `exposure' > r(p75)

sum `dist' if group == 0 , d
gen high_dist = `dist' > r(p50)

*compute employment shares
foreach var of varlist emp1980 emp1990 emp2000 emp2010 emp2018 {
	egen tot_emp = sum(`var'), by(group)
	replace `var' = `var'/tot_emp
	drop tot_emp
}

*save temp file with high exp occupation list
preserve
	keep if group == 0
	keep occ1990dd high_exp exposure_ict exposure_a
	rename high_exp high_exp75
	count
	save "$path_cleandata/temp_high_exp_late.dta", replace
restore

*collapse emp by pairs of high/low exposure/distance
collapse (sum) emp1980 emp1990 emp2000 emp2010 emp2018 (count) occ1990dd, by(high_exp high_dist group)

sort group high_exp high_dist

foreach p of numlist 1990 2000 2010 2018 {
	gen dlemp`p' = log( emp`p') - log( emp1980 )
}

*create output file for plot
keep if group == 0
keep high_exp high_dist dl*

save "$path_cleandata/exp_dist_plotICT.dta", replace

* Step 8: Robustness wrt sample for Table A2
********************************************************************************

foreach spec of numlist 2/3 {
	use "$path_cleandata/data_occ_1980_2010_s`spec'_a29.dta", clear

	*create variables for regressions)
	gen change_emp1 = log(emp1990/emp1980)
	gen change_emp2 = log(emp2000/emp1980)
	gen change_emp3 = log(emp2010/emp1980)
	gen change_emp4 = log(emp2018/emp1980)

	gen change_inc1  = lavgwage1990  - lavgwage1980 
	gen change_inc2  = lavgwage2000  - lavgwage1980
	gen change_inc3  = lavgwage2010  - lavgwage1980
	gen change_inc4  = lavgwage2018  - lavgwage1980 

	*select occupations with positive employment in 1980 and 2018
	gen aind = change_emp4 != .
	egen ind = sum(aind), by(occ1990dd)
	keep if ind == 3

	*weights
	gen aemp1980 = emp1980 if group == 0
	egen emp_all0 = mean(aemp1980), by(occ1990dd)

	*standardized exposure measures
	foreach var of varlist  ict {
		sum `var' if group == 0 [aw=emp_all0]
		gen exposure_`var' = (`var' - `r(mean)')/`r(sd)' 
	}
	
	*estimates
	local exposure exposure_ict
	local controls 
	
	gen variable = `exposure'
	gen aux_variable = .

	foreach p of numlist 2 4 {
		replace variable = `exposure'
		replace aux_variable = `exposure'
		reg change_emp`p' variable `controls' if group == 0  [aw = emp_all0] , cluster(occ1990dd)
		est sto per`p'_emp_s`spec'
		reg change_inc`p' variable `controls' if group == 0  [aw = emp_all0] , cluster(occ1990dd)
		est sto per`p'_inc_s`spec'
		
		replace variable = c.`exposure'#1.group
		replace aux_variable = c.`exposure'#2.group
		reg change_emp`p' variable aux_variable i.group `controls' if group >= 1  [aw = emp_all0]  , cluster(occ1990dd)
		est sto per`p'_group1_emp_s`spec'
		reg change_inc`p' variable aux_variable i.group `controls' if group >= 1  [aw = emp_all0]  , cluster(occ1990dd)
		est sto per`p'_group1_inc_s`spec'
		
		replace variable = c.`exposure'#2.group
		replace aux_variable = c.`exposure'#1.group
		reg change_emp`p' variable aux_variable i.group `controls' if group >= 1  [aw = emp_all0]  , cluster(occ1990dd)
		est sto per`p'_group2_emp_s`spec'
		reg change_inc`p' variable aux_variable i.group `controls' if group >= 1  [aw = emp_all0]  , cluster(occ1990dd)
		est sto per`p'_group2_inc_s`spec'	
		
		replace variable = c.`exposure'#1.group
		replace aux_variable = c.`exposure'#2.group
		reg change_emp`p' `exposure' variable aux_variable i.group `controls' if group >= 1  [aw = emp_all0]  , cluster(occ1990dd)
		est sto per`p'_dgroup_emp_s`spec'
		reg change_inc`p' `exposure' variable aux_variable i.group `controls' if group >= 1  [aw = emp_all0]  , cluster(occ1990dd)
		est sto per`p'_dgroup_inc_s`spec'
	}
	
}

* Step 9: Robustness wrt age cutoff for Figure A3
********************************************************************************

foreach Y of numlist 25/35 {
	use "$path_cleandata/data_occ_1980_2010_s1_a`Y'.dta", clear

	*create variables for regressions)
	gen change_emp4 = log(emp2018/emp1980)

	*Select occupations with positive employment in 1980 and 2018
	gen aind = change_emp4 != .
	egen ind = sum(aind), by(occ1990dd)
	keep if ind == 3

	*Weights
	gen aemp1980 = emp1980 if group == 0
	egen emp_all0 = mean(aemp1980), by(occ1990dd)

	*Standardized exposure measures
	foreach var of varlist ict {
		sum `var' if group == 0 [aw=emp_all0]
		gen exposure_`var' = (`var' - `r(mean)')/`r(sd)' 
	}

	local exposure exposure_ict

	reg change_emp4 	`exposure' c.`exposure'#1.group i.group `controls' if group >= 1 [aw = emp_all0]   , cluster(occ1990dd)
	est sto per4_difgroup_emp_a`Y'
}

*plot estimates: Figure A3
clear
set obs 11
gen p = _n
gen coef = .
gen SE = .
foreach Y of numlist 25/35 {
	est restore per4_difgroup_emp_a`Y'
	capture replace coef = _b[`exposure'#1.group] if p == `Y' - 24
	capture replace SE = _se[`exposure'#1.group] if p == `Y' - 24
}	
*compute 90CI  
scalar sig90 = 0.1
foreach sig in sig90 {
	capture gen up_`sig' = coef + invnormal(1-`sig'/2)*SE
	capture gen dn_`sig' = coef - invnormal(1-`sig'/2)*SE
}
export delimited using "$path_cleandata/FigA3_multiplecutoff_late.csv", replace

* Step 10: Export the estimates
********************************************************************************

*10.1: Export csv files to create Figure 1 for ICT
local exposure exposure_ict

foreach spec in emp inc group_emp group_inc dgroup_emp_base dgroup_inc_base {	
	clear
	set obs 4
	gen p = _n
	gen coef = .
	gen SE = .
	foreach i of numlist 1/2{		
		gen coef`i' = .
		gen SE`i' = .

		*import estimates
		foreach N of numlist 1/4 {
			est restore per`N'_`spec'
			if "`spec'" == "dgroup_emp_base" | "`spec'" == "dgroup_inc_base" {
				replace coef = _b[variable] if p == `N'
				replace SE = _se[variable] if p == `N'
			}
			else {
				capture replace coef = _b[`exposure'] if p == `N'
				capture replace SE = _se[`exposure'] if p == `N'
				capture replace coef`i' = _b[`exposure'#`i'.group] if p == `N'
				capture replace SE`i' = _se[`exposure'#`i'.group] if p == `N'
			}
		}

		*compute 90CI  
		scalar sig2 = 0.1
		capture gen up = coef + invnormal(1-sig2/2)*SE
		capture gen dn = coef - invnormal(1-sig2/2)*SE
		capture gen up`i' = coef`i' + invnormal(1-sig2/2)*SE`i'
		capture gen dn`i' = coef`i' - invnormal(1-sig2/2)*SE`i'
	}
	export delimited using "$path_cleandata/late_ict_`spec'.csv", replace
}

*10.2: Table A2 (Panel A): Effect of ICT on employment

* Baseline
esttab per2_emp_base per2_group1_emp_base per2_group2_emp_base per2_dgroup_emp_base per4_emp_base per4_group1_emp_base per4_group2_emp_base per4_dgroup_emp_base using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs style(tex)	///
		prehead("\begin{adjustbox}{width = \textwidth} \begin{tabular}{p{3.4cm}{c}*{8}{c}} \toprule")	///
		mgroups("\shortstack{\$t_0\$ and \$t_0+20\$ (mid-period)}" "\shortstack{\$t_0\$ and \$t_0+40\$ (full-period)}", pattern (1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) begin("Change between"))	///
		mlabels("\shortstack{All \\ 16-64yrs}" "\shortstack{Younger \\ 16-29yrs}" "\shortstack{Older \\ 30-64yrs}" "\shortstack{Younger - \\ Older}" "\shortstack{All \\ 16-64yrs}" "\shortstack{Younger \\ 16-29yrs}" "\shortstack{Older \\ 30-64}" "\shortstack{Younger - \\ Older}", begin("\shortstack{Worker group: \\ \ }"))	///
		posthead("\hline & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\ \hline\hline \multicolumn{9}{l}{\large{\textit{Panel A}: Effect of ICT exposure on relative employment}} \\[2pt]") ///
		varlabels(variable "Baseline", end("[4pt]"))	///
		collabels(none) nonumbers nocons nor2 noobs nonotes substitute(\_ \ \midrule "") replace

* Alternative exposure measure
esttab per2_emp_exposure_a per2_group1_emp_exposure_a per2_group2_emp_exposure_a per2_dgroup_emp_exposure_a per4_emp_exposure_a per4_group1_emp_exposure_a per4_group2_emp_exposure_a per4_dgroup_emp_exposure_a using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs style(tex) ///
		posthead("\multicolumn{9}{l}{Alternative exposure measure} \\")	///
		varlabels(variable "\hspace{3mm}Cognitive exposure", end("[4pt]"))	///
		collabels(none) mlabels(none) nonumbers nocons nor2 noobs nonotes substitute(\midrule "") append
		
* Alternative sample
esttab per2_emp_s2 per2_group1_emp_s2 per2_group2_emp_s2 per2_dgroup_emp_s2 per4_emp_s2 per4_group1_emp_s2 per4_group2_emp_s2 per4_dgroup_emp_s2 using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs style(tex) ///
		posthead("\multicolumn{9}{l}{Alternative sample} \\")	///
		varlabels(variable "\hspace{3mm}Only U.S. natives")	///
		collabels(none) mlabels(none) nonumbers nocons nor2 noobs nonotes substitute(\midrule "") append
esttab per2_emp_s3 per2_group1_emp_s3 per2_group2_emp_s3 per2_dgroup_emp_s3 per4_emp_s3 per4_group1_emp_s3 per4_group2_emp_s3 per4_dgroup_emp_s3 using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs style(tex) ///
		varlabels(variable "\hspace{3mm}Only white", end("[4pt]"))	///
		collabels(none) mlabels(none) nonumbers nocons nor2 noobs nonotes substitute(\midrule "") append

* Alternative control set
esttab per2_emp_controls per2_group1_emp_controls per2_group2_emp_controls per2_dgroup_emp_controls per4_emp_controls per4_group1_emp_controls per4_group2_emp_controls per4_dgroup_emp_controls using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs	style(tex) ///
		varlabels(variable "Alternative controls", end("[2pt] \bottomrule")) ///
		collabels(none) mlabels(none) nonumbers nocons nor2 noobs nonotes substitute(\midrule "") append
	
*10.3: Table A2 (Panel B): Effect of ICT on wage

* Baseline
esttab per2_inc_base per2_group1_inc_base per2_group2_inc_base per2_dgroup_inc_base per4_inc_base per4_group1_inc_base per4_group2_inc_base per4_dgroup_inc_base using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs style(tex)	///
		posthead("\multicolumn{9}{l}{\large{\textit{Panel B}: Effect of ICT exposure on relative wage}} \\[2pt]") ///
		varlabels(variable "Baseline", end("[4pt]"))	///
		collabels(none) mlabels(none) nonumbers nocons nor2 noobs nonotes substitute(\_ \ \midrule "") append

* Alternative exposure measure
esttab per2_inc_exposure_a per2_group1_inc_exposure_a per2_group2_inc_exposure_a per2_dgroup_inc_exposure_a per4_inc_exposure_a per4_group1_inc_exposure_a per4_group2_inc_exposure_a per4_dgroup_inc_exposure_a using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs style(tex) ///
		posthead("\multicolumn{9}{l}{Alternative exposure measure} \\")	///
		varlabels(variable "\hspace{3mm}Cognitive exposure", end("[4pt]"))	///
		collabels(none) mlabels(none) nonumbers nocons nor2 noobs nonotes substitute(\midrule "") append
		
* Alternative sample
esttab per2_inc_s2 per2_group1_inc_s2 per2_group2_inc_s2 per2_dgroup_inc_s2 per4_inc_s2 per4_group1_inc_s2 per4_group2_inc_s2 per4_dgroup_inc_s2 using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs style(tex) ///
		posthead("\multicolumn{9}{l}{Alternative sample} \\")	///
		varlabels(variable "\hspace{3mm}Only U.S. natives")	///
		collabels(none) mlabels(none) nonumbers nocons nor2 noobs nonotes substitute(\midrule "") append
esttab per2_inc_s3 per2_group1_inc_s3 per2_group2_inc_s3 per2_dgroup_inc_s3 per4_inc_s3 per4_group1_inc_s3 per4_group2_inc_s3 per4_dgroup_inc_s3 using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs style(tex) ///
		varlabels(variable "\hspace{3mm}Only white", end("[4pt]"))	///
		collabels(none) mlabels(none) nonumbers nocons nor2 noobs nonotes substitute(\midrule "") append

* Alternative control set
esttab per2_inc_controls per2_group1_inc_controls per2_group2_inc_controls per2_dgroup_inc_controls per4_inc_controls per4_group1_inc_controls per4_group2_inc_controls per4_dgroup_inc_controls using "$path_output/TableA2_robust.tex",	///
		keep(variable) cells(b(star fmt(%9.3f)) se(par)) starlevels(* 0.10 ** 0.05 *** 0.01) stats(,) fragment booktabs	style(tex) ///
		varlabels(variable "Alternative controls", end("[2pt] \bottomrule"))	///
		collabels(none) mlabels(none) nonumbers nocons nor2 noobs nonotes substitute(\midrule "") append


*10.4: Table A1

use "$path_cleandata/temp_high_exp_late.dta", clear

preserve
	keep occ1990dd exposure_ict
	gsort -exposure_ict
	gen rank = _n
	keep if rank <= 10
	merge 1:1 occ1990dd using "$path_rawdata/occ1990dd_desciption.dta"
	keep if _m == 3
	rename occ occ_ict
	keep rank occ_ict
	tempfile rank_occ_ict
	save `rank_occ_ict'
restore

keep occ1990dd exposure_a
gsort -exposure_a
gen rank = _n
keep if rank <= 10
merge 1:1 occ1990dd using "$path_rawdata/occ1990dd_desciption.dta"
sort rank
keep if _m == 3
rename occ occ_cognitive
keep rank occ_cognitive

merge 1:1 rank using `rank_occ_ict'
drop _merge
order rank occ_ict occ_cognitive
sort rank
